<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
    session_start();
    if(empty($_SESSION['playerid'])){
        if(empty($_REQUEST['submit'])){
?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Login - Mafia Game</title>

        <link href="css/login-box.css" rel="stylesheet" type="text/css" />
         <script src="js/jquery-1.9.1.js" 
type="text/javascript"></script>
        <script>
              $(document).ready(function () {
                   $('a.login').click(function(){
                       $('#frmLogin').submit();
                   });
              });
            
            
</script>
    </head>

    <body>
        <div style="padding: 100px 0 0 250px;">


            <div id="login-box">

                <H2>Login</H2>
              
                <br />
                <br />
                <form name="frmLogin" id="frmLogin" method="post">
                    <input type="hidden" name="submit" value="submit"/>
                <div id="login-box-name" style="margin-top:20px;">Email:</div><div id="login-box-field" style="margin-top:20px;"><input name="playerid" class="form-login" title="Player ID" value="" size="30" maxlength="2048" /></div>
                <div id="login-box-name">Password:</div><div id="login-box-field"><input name="pass" type="password" class="form-login" title="Password" value="" size="30" maxlength="2048" /></div>
                <br />
                <span class="login-box-options"><input type="checkbox" name="1" value="1"> Remember Me <a href="#" style="margin-left:30px;">Forgot password?</a></span>
                <br />
                <br />
                <input type="image" src="img/login-btn.png" width="103" height="42" style="margin-left:90px;" name="submit" alt="Login"/>
           
                   </form>
            </div>

        </div>
</body>
</html>
<?php
    }else{
        $playerid = $_REQUEST['playerid'];
     
        $pass = $_REQUEST['pass'];
    
        include_once ('db/db.php');
        $query = "select * from player where playerid='{$playerid}' AND pass='{$pass}'";
    
        $result = db::exec($query);
        if($result)
        {
            $login_rs=false;
            while ($row = mysql_fetch_array($result))
            {
                $login_rs=true;
            }
            if($login_rs)
            {
                $_SESSION['playerid']=$playerid;
                header("Location: processing.php");
            }
            else
            {
                echo "PlayerId or Password is not correct";
            }
        }
        else
        {
            echo "System failed";
        }
    }
    }else{
        header("Location: processing.php");
    }
        
    
?>
